﻿Imports System
Imports System.Web.UI
Imports System.Collections.Generic
Imports SISSAT.WebDevelopment.Views
Imports SISSAT.BusinessLayer.Views
Imports SISSAT.BusinessLayer.DataViews

Namespace [Shared].UserControls
    Public Class GradePointAverageControl
        Inherits UserControl
        Implements IGradePointAverageControlView

        Private Presenter As GradePointAverageControlPresenter
        Public IsReadOnly As Boolean

        Public Property GradePointAverage As Decimal Implements IGradePointAverageControlView.GradePointAverage
        Public Property TotalUnits As Decimal Implements IGradePointAverageControlView.TotalUnits
        Public ReadOnly Property SelectedValue As String Implements IGradePointAverageControlView.SelectedValue
            Get
                Dim selected As String = schoolYearDropDownList.SelectedControlValue
                If IsReadOnly Then
                    selected = HttpContext.Current.Request.QueryString("sys")
                End If

                Return selected
            End Get
        End Property

        Public ReadOnly Property StudentCode As String Implements IGradePointAverageControlView.StudentCode
            Get
                Return SISSATPageBase.User.Employee.EmployeeCode
            End Get
        End Property

        Public ReadOnly Property StudentId As Integer Implements IGradePointAverageControlView.StudentId
            Get
                Return SISSATPageBase.User.Employee.EmployeeId
            End Get
        End Property

        Public WriteOnly Property DropDownListDataSource As IEnumerable(Of KeyValuePair(Of String, String)) Implements IGradePointAverageControlView.DropDownListDataSource
            Set(value As IEnumerable(Of KeyValuePair(Of String, String)))
                schoolYearDropDownList.DataSource = value
            End Set
        End Property

        Public WriteOnly Property RepeaterDataSource As IEnumerable(Of GradePointAverageDataView) Implements IGradePointAverageControlView.RepeaterDataSource
            Set(value As IEnumerable(Of GradePointAverageDataView))
                reportCardRepeater.DataSource = value
                reportCardRepeater.DataBind()
            End Set
        End Property

        Public Event OnInitialization(isReadOnly As Boolean) Implements IGradePointAverageControlView.OnInitialization
        Public Event OnSelectedIndexChange() Implements IGradePointAverageControlView.OnSelectedIndexChange

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            schoolYearDropDownList.IsReadOnly = IsReadOnly
            Presenter = New GradePointAverageControlPresenter(Me)

            RaiseEvent OnInitialization(IsReadOnly)
            RaiseEvent OnSelectedIndexChange()
        End Sub

        Protected Sub SelectedIndexChange(sender As Object, e As System.EventArgs) Handles schoolYearDropDownList.SelectedIndexChanged
            RaiseEvent OnSelectedIndexChange()
        End Sub

    End Class
End Namespace
